Skip to content

Feature/exception handler - #31

Merged
simonforsberg merged 15 commits into
mainfrom
feature/exception-handler
Apr 21, 2026
Merged

Feature/exception handler#31
simonforsberg merged 15 commits into
mainfrom
feature/exception-handler

Conversation

@FionaSprinkles

@FionaSprinkles FionaSprinkles commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Added custom error handling and replaced Spring Boot whitelabel pages.

Summary by CodeRabbit

  • New Features
    • Custom error pages and template added for 401 (unauthorized) and 403 (forbidden) responses.
    • Centralized exception handling shows user-friendly messages and proper HTTP statuses.
    • Security rules refined: public access limited to the home/start pages and specific ticket creation endpoint; all error paths are publicly accessible.
    • Default whitelabel error page disabled.

@coderabbitai

coderabbitai Bot commented Apr 20, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@FionaSprinkles has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 12 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 49 minutes and 12 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3146b4f1-de0f-42ee-8d8c-f507838e8611

📥 Commits

Reviewing files that changed from the base of the PR and between ce0e5a3 and 708f9fb.

📒 Files selected for processing (1)
  • src/main/jte/error.jte
📝 Walkthrough

Walkthrough

Updated security and error handling: tightened authorization rules, added custom forwarding for 401/403 to new error endpoints, introduced an ErrorController and global exception handler, added an error JTE template, and disabled Spring Boot's whitelabel error page.

Changes

Cohort / File(s) Summary
Security & Config
src/main/java/org/example/alfs/config/SecurityConfig.java, src/main/resources/application.properties
Tightened HTTP authorization (explicitly permit / and /startPage; allow only unauthenticated GET /tickets/create; removed blanket /tickets/** permit). Added forwarding for access-denied (403) → /error/403 and unauthenticated (401) → /error/401. Disabled whitelabel error page.
Error Controllers
src/main/java/org/example/alfs/controllers/ErrorController.java
Added ErrorController with GET handlers for /error/403 and /error/401 returning the error view and setting respective response statuses.
Exception Handling
src/main/java/org/example/alfs/exceptions/GlobalExceptionHandler.java
Added @ControllerAdvice with handlers for ResponseStatusException (uses status and reason) and generic Exception (sets 500 and fixed message), both returning the error view.
View Template
src/main/jte/error.jte
New JTE template error.jte accepting String error and Integer status, rendering an error page with status, message, and a link to /startPage.

Sequence Diagram

sequenceDiagram
    participant Client
    participant SecurityFilter as Security Filter
    participant ErrorController as Error Controller
    participant ExceptionHandler as Global Exception Handler
    participant JTETemplate as error.jte Template

    Client->>SecurityFilter: HTTP request
    SecurityFilter->>SecurityFilter: Authorization/authentication check

    alt Access Denied (403)
        SecurityFilter->>ErrorController: Forward to /error/403
        ErrorController->>JTETemplate: Render error(status=403, error="Access denied")
        JTETemplate->>Client: HTML 403 page
    else Authentication Failed (401)
        SecurityFilter->>ErrorController: Forward to /error/401
        ErrorController->>JTETemplate: Render error(status=401, error="You need to log in to access this page")
        JTETemplate->>Client: HTML 401 page
    else Other Exception
        SecurityFilter->>ExceptionHandler: Exception propagated
        ExceptionHandler->>JTETemplate: Render error(status, message)
        JTETemplate->>Client: HTML error page
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰
I hopped through filters, found a gap in sight,
Now 401s and 403s bounce to the light.
A gentle page shows what went wrong,
With a button home where bunnies belong. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feature/exception handler' is partially related to the changeset. While exception handling is introduced, the PR's primary scope is broader—it encompasses custom error handling, error pages, security configuration changes, and exception handler routing. The title captures only one aspect (exception handler) and omits the core feature context (error handling replacement).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/exception-handler

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/org/example/alfs/controllers/ErrorController.java`:
- Around line 12-23: In ErrorController, update the forbidden(...) and
unauthorized(...) handlers to accept forwarded non-GET requests and set the real
HTTP status: replace `@GetMapping`("/403") with `@RequestMapping`("/403") and
annotate the forbidden method with `@ResponseStatus`(HttpStatus.FORBIDDEN);
likewise replace `@GetMapping`("/401") with `@RequestMapping`("/401") and annotate
unauthorized with `@ResponseStatus`(HttpStatus.UNAUTHORIZED); keep the same Model
usage and return values, and add the necessary imports for ResponseStatus and
HttpStatus in the ErrorController class.

In `@src/main/java/org/example/alfs/exceptions/GlobalExceptionHandler.java`:
- Around line 11-26: The handlers handleResponseStatusException and
handleException need to set the actual HTTP response status before returning the
view; add a HttpServletResponse parameter to each method and call
response.setStatus(...)—for handleResponseStatusException use
ex.getStatusCode().value() and for handleException use 500—so the servlet
returns the correct HTTP status instead of 200 while still populating the model
and returning "error".

In `@src/main/jte/error.jte`:
- Around line 1-3: The template declares a required parameter "ex" that is never
used and not provided by ErrorController/GlobalExceptionHandler; remove the
"@param org.example.alfs.exceptions.GlobalExceptionHandler ex" declaration from
the error.jte header so only the actual parameters ("error" and "status") remain
declared, ensuring the template can render without the missing required "ex"
parameter.

In `@src/main/resources/application.properties`:
- Around line 4-5: The property key is incorrect: replace the unrecognized
spring.web.error.whitelabel.enabled with the correct Spring Boot property
server.error.whitelabel.enabled so the whitelabel error page setting is applied;
update the configuration entry that currently reads
spring.web.error.whitelabel.enabled=false to use
server.error.whitelabel.enabled=false.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 66663ce4-89cd-4567-8fff-caa170432657

📥 Commits

Reviewing files that changed from the base of the PR and between 35fef5c and 95346b3.

📒 Files selected for processing (5)
  • src/main/java/org/example/alfs/config/SecurityConfig.java
  • src/main/java/org/example/alfs/controllers/ErrorController.java
  • src/main/java/org/example/alfs/exceptions/GlobalExceptionHandler.java
  • src/main/jte/error.jte
  • src/main/resources/application.properties

Comment thread src/main/java/org/example/alfs/controllers/ErrorController.java Outdated
Comment thread src/main/jte/error.jte Outdated
Comment thread src/main/resources/application.properties
@simonforsberg
simonforsberg merged commit 8cd25ed into main Apr 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants